package graph_viewer.structure;

import java.awt.Graphics;
import java.util.*;

import graph_viewer.canvas.*;


public abstract class Tree extends Basic_Graph{
	//============================================================================
	// getter & setter
	//============================================================================
	abstract public ArrayList		get_tree();
	abstract public Node		get_root();
	abstract public void			set_tree( ArrayList a_tree_node_list );
	abstract public void			set_root( Node a_node );
		
	public String		get_class_name(){
		return Visual_Component.TREE;
	}

	//============================================================================
	// public interface
	//============================================================================
	//of Graph	
	abstract public void			traverse( Command action );
	abstract public Node		search( String label );
	abstract public ArrayList		find_edges();
	abstract public void			allocate_DOI( Node focus_node );

	// template hooker
	abstract protected void		draw_edges( final Graphics g, final Canvas_Metrics cm );
	abstract protected void		draw_nodes( final Graphics g, final Canvas_Metrics cm ) ;
	abstract protected void		draw_clsuters( final Graphics g, final Canvas_Metrics cm );	

	//of Tree
	abstract public void		add_node( Node a_node );
	abstract public void		delete_node( Node a_node );
	abstract public void		empty();	
	abstract public boolean	is_empty();
	abstract public void		reset_tree( Tree atree );//set the tree data as atree
	
	abstract public int			depth( Node a_tree_node );
	abstract public int			height();
	abstract public boolean		is_leaf( Node a_node );
	abstract public boolean		is_root( Node a_node );
	abstract public boolean		is_ancestor( Node anc, Node desc );
	abstract public ArrayList		get_ancesters( Node a_node );
	abstract public Node		get_parent(Node a_node);
	abstract public ArrayList		find_descedants( Node tn );

	// one level nodes are set in a ArrayList; all the ArrayList are set in the return ArrayList
	// the root is at the first level
	public ArrayList find_nodes_in_all_level(){
		ArrayList level_nodes	= new ArrayList();

		int h	= height();

		for ( int i = 0; i <=h ; i++ ){
			ArrayList level_i_nodes	= find_same_height_nodes( i );
			level_nodes.add( level_i_nodes );
		}

		return level_nodes;
	}
}